package com.jt.aop;

import com.jt.anno.Pri;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.List;
import java.util.Vector;

@Component
@Aspect     //标识切面
public class SpringAOP {

    private List<String> list = new Vector<>();

    @PostConstruct  //在对象创建之后立即调用
    public void init(){

        list.add("add");
        list.add("update");
    }

    @Around("@annotation(pri)")
    public Object around(ProceedingJoinPoint joinPoint, Pri pri) throws Throwable {
        String name = pri.name();
        System.out.println("用户的权限："+name);
        if(list.contains(name)){
            Object proceed = joinPoint.proceed();
            return proceed;
        }else {
            System.out.println("用户没有权限");
        }
        return null;
    }



}
